const fs = require('fs')
const path  = require('path')

//生成写入的文件
function createWriteStream(fileName) {
    const fullFileNanme = path.join(__dirname, '../','../','logs',fileName)
    const writeStream = fs.createWriteStream(fullFileNanme, {
        flags: 'a' //累加写入为a，覆盖为w
    })
    return writeStream
}

const accessWriteStream = createWriteStream('access.log')

//写日志
function writeLog(writeStream, log) {
    writeStream.write(log + '\n') //写入
}


//写访问日志
function  access(log) {
    writeLog(accessWriteStream,log)
}

module.exports = {
    access
}